home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
1116.ZIP
/
TUTOR.DOC
< prev
Wrap
Text File
|
1988-09-22
|
14KB
|
283 lines
WHY USE SMALL C ?
SmallC:PC, adapted for use in MS-DOS by Caprock Systems,
Inc., has been circulated by public domain distributors for
several years now. This nice subset compiler, complete with its
own source code (CPC.*) and linkable run-time module (CPCLIB.*)
is usually found buried among a collection of uncompiled C
programs that will not run under Small C. Some attention should
be given to this C compiler, because it works, it is easy to use,
and it can run on not-so-PC-compatibles.
Recalling my own first encounter with Small C, and comments
from friends who had at one time or another sought to whip up
something in Small C, I suspect that many would-be Small C
programmers never get past the CPC compile phase. But, let me
assure you, the compiler does work. It also locates and describes
program errors very clearly at compile time on your CRT. The
following two tips may be all you need to get up and running.
In contemporary zeitgeist, printf("Hello") is the function
call of "the minimal C program". Unfortunately, printf() does not
exist in CPCLIB.*. If puts("Hello") is used in Small C there is
no problem, and this is standard syntax, supported by the popular
C compilers such as Lattice C. So, this is "the minimal Small C
program":
/* the minimal Small C program */
main()
{
puts("Hello");
}
Another rudimentary pitfall is in the non-standard Small C
syntax used to include header files. The usual syntax would look
like this: #include<stdio.h> or like: #include"stdio.h"
Small c syntax is different, since the prevailing incarnation
of the compiler does not do enough parsing of the '#include'
instruction to accomodate the standard C syntax. So, to include
the header file MYFILE.H, use #include MYFILE.H or #include
B:MYFILE.H . The header file is not pre-compiled, but it must
exist and be accessible during CPC compilation. As with your
Small C program source code, your Small C header files are simple,
flat ASCII files created with any text editor you like. Here is an
example:
/* this is a Small C header file named NOISE.H */
buzzer()
{
putchar(7);
}
Here is an example Small C program that includes NOISE.H:
/* this program sounds the console bell */
#include noise.h
main()
{
buzzer();
}
SO WHAT'S THE ADVANTAGE TO USING SMALL C ?
On disk, the resolved run-time module is just under 4K bytes,
as opposed to 11K bytes in Pascal or 18K to 20K for the BASIC,
COBOL, and ForTran compiler packages you are likely to find.
This is a significant difference, and the effects are often
cumulative for those of us who write short batch utility programs,
and it is an expedient alternative to programming in assembler at
a minimized cost in disk space.
Also, Small-c:PC is still probably the easiest C language
implementation to set up and use, given a little guidance.
SO WHAT DO I WANT THIS DISK FOR ?
Commercial full C compilers are usually packaged with many
ready-to-use header files. Unfortunately, Small C cannot make use
of these files, because the STRUCT and UNION constructs have not
been implemented in Small C, and most of the standard header files,
such as STDIO.H, usually use these constructs.
Aside from this Small-c:PC tutorial, this disk contains the
header files STDIO.H and GETINT.H. These two header files, and the
other header files on this disk, make Small C practical and useful.
DO I NEED TO BE AN ASSEMBLY LANGUAGE EXPERT TO USE SMALL C ?
NO. A study of the header files will reveal that I used in-line
assembler in only one header, PUTRCHAR.H, for the putrchar() function.
Also, since STDIO.H and GETINT.H are now available to you, your Small
c programs will not have to be shrouded in uncertainties or various
and rambling I/O experimentations.
WHAT IS THE SEQUENCE OF EVENTS THAT RESULTS IN A FINISHED PROGRAM ?
1. Use a text editor to write your Small C program.
A. Convention would be to use *.C as the filename extension.
2. Use CPC.EXE, the public domain Small-c:PC compiler.
A. Convention here would be to use *.ASM as the filename,
since CPC.EXE creates a file that is the assembly
language equivalent of your Small C program.
3. Use MASM.EXE, the Microsoft Macro Assembler, or any public
domain assembler that can be used to create *.EXE files.
A. The file that you assemble is the *.ASM file created by
CPC.EXE in step 2.
B. Convention here would be to name the object file created
by MASM.EXE using the filename extension *.OBJ
4. Use LINK.EXE, the Microsoft linker that is found on your
original MS-DOS or PC-DOS or TRS-DOS system disk.
A. LINK.EXE goes like this:
A>LINK
OBJECT MODULES[.OBJ]: MYPROG.OBJ
RUN FILE [MYPROG.EXE]: MYPROG.EXE
MAP FILE [.MAP]: <cr>
LIBRARIES [.LIB]: CPCLIB.LIB
B. This creates MYPROG.EXE
5. A>MYPROG (This executes your program directly in MS-DOS)
Below is a directory listing the documentation files on this disk:
DECOM DOC Documentation and source code for DECOM.COM
HEXPRINT DOC Documentation for HEXPRINT.C
MLBAT DOC Documentation for ML1.BAT ML2.BAT and ML3.BAT
SOUNDEX DOC Documentation for SOUNDEX.C (a simple demo program)
README DOC Quick reference of functions in each header file
TUTOR DOC This Small C tutorial.
6 File(s)
---------------------------------------------------------------------
ADVANCED SMALL C TOPICS:
Below is the multi-segment envelope into which Small-c:PC packages
all programs. The high-level Small-c source code for the tiny example
program below has been rewritten in assembly code by the CPC.EXE
compiler. The CPC compilation simply creates a new additional file
that is the assembly language source code equivalent of the Small-c:PC
program source code.
main() \
{ \_____ SHELL.C created by me as Small-c:PC
} / program source code.
/ (Created via a text editor.)
;* * * Small-C:PC V1.1 * * * \
;PC-DOS Version N: June, 1982 \
;By Ron Cain, Modified by CAPROCK SYSTEMS \
; \
CSEG SEGMENT BYTE PUBLIC 'code' \
ASSUME CS:CSEG,SS:STACK \
;main() \
PUBLIC QZMAIN \
QZMAIN: \
;{ \____ SHELL.ASM
;} / created by
RET / CPC.EXE
CSEG ENDS /
DUMMY SEGMENT BYTE STACK 'dummy' /
DUMMY ENDS /
STACK SEGMENT BYTE PUBLIC 'stack' /
STACK ENDS /
; --- End of Compilation --- /
END /
DECOM.COM can be used to reduce the size of Small-c *.ASM files.
It strips away assembler code comment lines. The code listed below
is the Small-c multi-segment envelope, in perhaps more readable form.
As you can see, DECOM.COM was used to strip away the comment lines.
DECOM.COM will probably be useful only if you are still limited to
single-sided floppy disks or if you are inclined toward including
header files rather than linking object modules.
CSEG SEGMENT BYTE PUBLIC 'code' \
ASSUME CS:CSEG,SS:STACK \
PUBLIC QZMAIN \
QZMAIN: \
RET \_______ SHELL.ASM after DECOM
CSEG ENDS /
DUMMY SEGMENT BYTE STACK 'dummy' /
DUMMY ENDS /
STACK SEGMENT BYTE PUBLIC 'stack' /
STACK ENDS /
END /
An important point to remember here is that the Small-c:PC envelope is a
multi-segment package. This means that you can not use EXE2BIN in MS-DOS
to convert your finished *.EXE program files into *.COM files. It also means
that your Small-c:PC programs are not necessarily limited to a small model
(which would be 64 Kbytes in MS-DOS).
A side note also worth mentioning here is that the CPC.EXE compiler will
compile your header files by themselves, so that you can transform them
into *.ASM files, and then into *.OBJ files using MASM. The fact that
main() is missing does not produce a compile error. This practice of
turning your header routines into linkable *.OBJ modules will make
program development in Small-c:PC a pleasure, because it greatly reduces
CPC compile time as well as MASM assembly time, and the increase in LINK
time is hardly noticeable. This also conserves disk space which would
otherwise be quickly swallowed up in *.ASM files. The run-time file
CPCLIB.OBJ is a linkable *.OBJ file (sometimes CPCLIB.ASM and CPCLIB.OBJ
have been distributed in the public domain and sometimes CPCLIB.LIB is
distributed). See ML2.BAT and ML3.BAT and HELLO3.C for linkage examples.
CPCLIB.* is the run-time module. You must link either CPCLIB.LIB or
CPCLIB.OBJ to your program object file in order to produce an *.EXE file.
If you do not link CPCLIB.* then a linkage error will occur, and you will
simply have to try LINK again.
Below is a directory of the Small-c:PC example program source code files.
Any of the new functions used in a program are listed on the right.
BARS C 241 hbar() vbar() cls550()
BLANKING C 783 blank() nochars() cursor() cls550()
CLS550 C 138 cls550()
CTYPE C 610 toupper() tolower()
CULATOR C 131 culator()
CURSOR C 242 cursor()
GETNUM C 1219 getint() getval() printf() cls550()
HELLO1 C 73 uses CPCLIB.* functions only
HELLO2 C 100 printf()
HELLO3 C 422 printf()
HEXPRINT C 342 hexprint()
MODE C 547 findmode() color() vblock()
NOT C 468 not() printf()
PUTRCHAR C 528 putrchar() putrs()
SOUNDEX C 3836 uses CPCLIB.* functions only
STATS C 1435 min() max() size() occ() span() lactd() sactd()
printf() cls550()
STRING C 461 strlen() strpos() printf()
WINDOW C 262 window()
_FILES C 1269 fprintf()
_STDIO C 523 printf() prnstr() prnchar()
20 File(s)
Below is a directory of the Small-c:PC header file source code files.
All functions in any particular *.H file are listed on the right.
Study of the source code in these header files will reveal that none
of the *.H files are dependent on functions found only in other *.H
files. -This means that you can include or link any or all of them.
BARS H 852 vbar() hbar()
BLANKING H 1565 blank() nochars()
CLS550 H 438 cls550()
CTYPE H 707 toupper() tolower()
CULATOR H 6547 culator()
CURSOR H 337 cursor()
GETINT H 8170 getint() getval()
MODE H 1122 setmode() findmode() color() vblock()
NOT H 1055 not()
PUTRCHAR H 1230 putrchar() putrs()
STATS H 5204 min() max() size() lactd() sactd() occ() span()
STDIO H 8848 printf() prnchar() prnstr() prnf()
STRING H 2623 strlen() strpos() charpos()
WINDOW H 600 window()
_FILES H 8343 hexprint() fprintf()
15 File(s)
If you have followed me through to this point with no problem then you
are an experienced PC programmer, and you are ready to take note that
the video functions are currently not doing any paging. All video
control uses the BIOS interrupt 10h in page 0. This was done to simplify
and shorten the list of values sent to the new functions. And, since I
have provided the functions in source code form, a programmer familiar
with BIOS interrupt 10h can easily implement the changes to allow for
video paging on color screens, if the need arises.
THIS DISK IS INTENDED FOR PUBLIC DOMAIN DISTRIBUTION. NO EXPRESS
OR IMPLIED GUARANTEE AS TO THE FUNCTIONALITY OF ANY SOFTWARE ON
DISK FOR ANY SPECIFIC PURPOSE IS INTENDED. I HAVE SUBMITTED THIS
DISK TO PUBLIC DOMAIN DISTRIBUTION TO PROMOTE THE USE OF SMALL-C,
IN THE HOPE THAT MORE SMALL-C HEADERS AND FUNCTIONS WILL BECOME
AVAILABLE TO ME IN THE PUBLIC DOMAIN FROM OTHER INTERESTED USERS.
Wayne Pearson
RD2 Box 5533
Montpelier, VT 05602